package sdfi.lee.Entity.base;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * This is an object that contains data related to the enterprise table.
 * Do not modify this class because it will be overwritten if the configuration file
 * related to this class is modified.
 *
 * @hibernate.class
 *  table="enterprise"
 */

public abstract class BaseEnterprise  implements Serializable {

	public static String REF = "Enterprise";
	public static String PROP_EPDESCRIBE = "epdescribe";
	public static String PROP_EPTYPE = "eptype";
	public static String PROP_ID = "id";
	public static String PROP_EPPHONE = "epphone";
	public static String PROP_EPLINKMAN = "eplinkman";
	public static String PROP_EPNAME = "epname";


	// constructors
	public BaseEnterprise () {
		initialize();
	}

	/**
	 * Constructor for primary key
	 */
	public BaseEnterprise (java.lang.Integer id) {
		this.setId(id);
		initialize();
	}

	protected void initialize () {}



	private int hashCode = Integer.MIN_VALUE;

	// primary key
	private java.lang.Integer id;

	// fields
	private java.lang.String epname;
	private java.lang.String eplinkman;
	private java.lang.String epphone;
	private java.lang.Integer eptype;
	private java.lang.String epdescribe;
	private java.lang.String eppath;
	// collections
	private java.util.Set<sdfi.lee.Entity.Drug> drugs;



	/**
	 * Return the unique identifier of this class
     * @hibernate.id
     *  generator-class="identity"
     *  column="Id"
     */
	public java.lang.Integer getId () {
		return id;
	}

	/**
	 * Set the unique identifier of this class
	 * @param id the new ID
	 */
	public void setId (java.lang.Integer id) {
		this.id = id;
		this.hashCode = Integer.MIN_VALUE;
	}




	/**
	 * Return the value associated with the column: epname
	 */
	public java.lang.String getEpname () {
		return epname;
	}

	/**
	 * Set the value related to the column: epname
	 * @param epname the epname value
	 */
	public void setEpname (java.lang.String epname) {
		this.epname = epname;
	}



	/**
	 * Return the value associated with the column: eplinkman
	 */
	public java.lang.String getEplinkman () {
		return eplinkman;
	}

	/**
	 * Set the value related to the column: eplinkman
	 * @param eplinkman the eplinkman value
	 */
	public void setEplinkman (java.lang.String eplinkman) {
		this.eplinkman = eplinkman;
	}



	/**
	 * Return the value associated with the column: epphone
	 */
	public java.lang.String getEpphone () {
		return epphone;
	}

	/**
	 * Set the value related to the column: epphone
	 * @param epphone the epphone value
	 */
	public void setEpphone (java.lang.String epphone) {
		this.epphone = epphone;
	}



	/**
	 * Return the value associated with the column: eptype
	 */
	public java.lang.Integer getEptype () {
		return eptype;
	}

	/**
	 * Set the value related to the column: eptype
	 * @param eptype the eptype value
	 */
	public void setEptype (java.lang.Integer eptype) {
		this.eptype = eptype;
	}



	/**
	 * Return the value associated with the column: epdescribe
	 */
	public java.lang.String getEpdescribe () {
		return epdescribe.replace("/project", "");
	}

	/**
	 * Set the value related to the column: epdescribe
	 * @param epdescribe the epdescribe value
	 */
	public void setEpdescribe (java.lang.String epdescribe) {
		this.epdescribe = epdescribe;
	}



	/**
	 * Return the value associated with the column: drugs
	 */
	public java.util.Set<sdfi.lee.Entity.Drug> getDrugs () {
		return drugs;
	}

	/**
	 * Set the value related to the column: drugs
	 * @param drugs the drugs value
	 */
	public void setDrugs (java.util.Set<sdfi.lee.Entity.Drug> drugs) {
		this.drugs = drugs;
	}
	
	public java.lang.String getEppath() {
		this.getPath(this.epdescribe);
		return eppath;
	}

	public void setEppath(java.lang.String eppath) {
		this.eppath = eppath;
	}
	
	public void addTodrugs (sdfi.lee.Entity.Drug drug) {
		if (null == getDrugs()) setDrugs(new java.util.TreeSet<sdfi.lee.Entity.Drug>());
		getDrugs().add(drug);
	}




	public boolean equals (Object obj) {
		if (null == obj) return false;
		if (!(obj instanceof sdfi.lee.Entity.Enterprise)) return false;
		else {
			sdfi.lee.Entity.Enterprise enterprise = (sdfi.lee.Entity.Enterprise) obj;
			if (null == this.getId() || null == enterprise.getId()) return false;
			else return (this.getId().equals(enterprise.getId()));
		}
	}

	public int hashCode () {
		if (Integer.MIN_VALUE == this.hashCode) {
			if (null == this.getId()) return super.hashCode();
			else {
				String hashStr = this.getClass().getName() + ":" + this.getId().hashCode();
				this.hashCode = hashStr.hashCode();
			}
		}
		return this.hashCode;
	}


	public String toString () {
		return super.toString();
	}
	private void getPath(String source)
	{
		try
		{
			if(source!=null&&source.length()>0)
			{
				String regex="/userfiles.*[jpg][gif]";
				Pattern p=Pattern.compile(regex);
				Matcher m=p.matcher(source);
				if(m.find())
				{
					this.setEppath(m.group().replace("/project", ""));
					//System.out.println(m.group().replace("/project", ""));
				}
			}
		}
		catch(Exception ee)
		{
			
		}
	}


}